package com.villaday.idf.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.villaday.idf.R;
import com.villaday.idf.model.PublicEntity;
import com.villaday.idf.model.vipsGroupsEntity;
import com.villaday.idf.util.PhoneUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2018/8/14.
 */
public class GroupManageAdapter extends BaseAdapter {
    private Context mContext;
    private List<vipsGroupsEntity.BodyBean.MembersBean> mList = new ArrayList<>();
    private boolean mListType = true;//是否显示全部成员,默认显示

    public void setNumber(boolean mListType) {
        this.mListType = mListType;
    }

    public GroupManageAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void replace(List<vipsGroupsEntity.BodyBean.MembersBean> itemDataTypes) {
        mList.clear();
        if (itemDataTypes.size() > 0) {
            mList.addAll(itemDataTypes);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return mListType ? mList.size() : 5;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_gridview, null);
            convertView.setBackgroundColor(Color.TRANSPARENT);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String mPic = mList.get(position).getHeaderUrl();
        holder.sdv.setImageURI(PhoneUtil.getHead(mPic));
        holder.mTvName.setText(mList.get(position).getNickName());
        if (position == mList.size() - 1) {
            holder.ivAddMember.setVisibility(View.VISIBLE);
            holder.llMermberLayput.setVisibility(View.GONE);
        } else {
            holder.ivAddMember.setVisibility(View.GONE);
            holder.llMermberLayput.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.sdv_head)
        SimpleDraweeView sdv;
        @BindView(R.id.tv_numItemNumber)
        TextView mTvName;
        @BindView(R.id.icon_add_member)
        ImageView ivAddMember;
        @BindView(R.id.ll_mermber_layout)
        LinearLayout llMermberLayput;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);

        }
    }
}
